<template>
  <Form ref="form" :model="form" :rule="rule" :label-width="100">
      <FormItem label="有效期" prop="endTime">
        <DatePicker @on-change="handleChange" type="daterange" placement="bottom-end" placeholder="选择有效期"></DatePicker>
      </FormItem>
    </Form>
</template>
<script>
import { setApplyRecordStartAndEndTime } from '@/api/wzyy/wzyy.cloudbaebatch.service.js'
export default {
  props: {
    params: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      form: {
        cloubdaeBatchId: '',
        startTime: '',
        endTime: ''
      },
      rule: {
        endTime: [
          { required: true, message: '有效期不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleChange (s) {
      if (s.length === 2) {
        this.form.startTime = s[0] + ' 00:00:00'
        this.form.endTime = s[1] + ' 23:59:59'
      }
    },
    submit () {
      this.form.cloubdaeBatchId = this.params.id
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            setApplyRecordStartAndEndTime(this.form).then(res => {
              if (res.code === 0) {
                resolve({
                  code: 0,
                  msg: '设置有效期成功'
                })
              } else {
                resolve({
                  code: res.code,
                  msg: res.msg
                })
              }
            })
          } else {
            reject(new Error('error'))
          }
        })
      })
    }
  }
}
</script>
